
using System;
using System.Data;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using PuntoMascotasWeb.BackEnd.BE;

namespace PuntoMascotasWeb.BackEnd.DAC
{
  /// <summary>
  /// TableDataGateway para Tarjetas.
  /// </summary>
  /// <Date>2013-05-05T15:02:35</Date>
  /// <Author>Mx23</Author>
  public class TarjetasDAC
  {
    /// <summary>
    /// Insert
    /// </summary>
    /// <param name="pTarjetasBE">TarjetasBE</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Insert(TarjetasBE pTarjetasBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Tarjetas_i");

        /// IdTarjeta
        wDataBase.AddOutParameter(wCmd, "IdTarjeta", System.Data.DbType.Int32, 4);
        /// Descripcion
        wDataBase.AddInParameter(wCmd, "Descripcion", System.Data.DbType.String, pTarjetasBE.Descripcion);
        /// Borrado
        wDataBase.AddInParameter(wCmd, "Borrado", System.Data.DbType.String, pTarjetasBE.Borrado);
        /// IdTipoTarjeta
        wDataBase.AddInParameter(wCmd, "IdTipoTarjeta", System.Data.DbType.Int32, pTarjetasBE.IdTipoTarjeta);

        wDataBase.ExecuteNonQuery(wCmd);
        pTarjetasBE.IdTarjeta = (System.Int32)wDataBase.GetParameterValue(wCmd, "IdTarjeta");
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Update
    /// </summary>
    /// <param name="pTarjetasBE">TarjetasBE</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Update(TarjetasBE pTarjetasBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Tarjetas_u");

        /// IdTarjeta
        wDataBase.AddInParameter(wCmd, "IdTarjeta", System.Data.DbType.Int32, pTarjetasBE.IdTarjeta);
        /// Descripcion
        wDataBase.AddInParameter(wCmd, "Descripcion", System.Data.DbType.String, pTarjetasBE.Descripcion);
        /// Borrado
        wDataBase.AddInParameter(wCmd, "Borrado", System.Data.DbType.String, pTarjetasBE.Borrado);
        /// IdTipoTarjeta
        wDataBase.AddInParameter(wCmd, "IdTipoTarjeta", System.Data.DbType.Int32, pTarjetasBE.IdTipoTarjeta);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Delete
    /// </summary>
    /// <param name="pIdTarjeta">IdTarjeta</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Delete(System.Int32 pIdTarjeta)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Tarjetas_d");

        /// IdTarjeta
        wDataBase.AddInParameter(wCmd, "IdTarjeta", System.Data.DbType.Int32, pIdTarjeta);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetAll
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetAll()
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Tarjetas_s");


        return wDataBase.ExecuteDataSet(wCmd);
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetByParam
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetByParam(int pPageNum, int pPageSize)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Tarjetas_sp");


        /// pPageNum
        wDataBase.AddInParameter(wCmd, "PageNum", System.Data.DbType.Int32, pPageNum);
        /// PageSize
        wDataBase.AddInParameter(wCmd, "PageSize", System.Data.DbType.Int32, pPageSize);

        return wDataBase.ExecuteDataSet(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }
  }
}